program ChromeRefactorAssessment;

include <core.vhs>
include <shell.vhs>
include "chrome.vhs"

import core::*;
import core::Pattern::*;
import core::Logging::*;

function main(output='/home/vhnguyen/analysis/chrome/refactor/', base='/storage/vhnguyen/chrome/') {
	for (var i = 0; i < 19; i++)
		genFileList(i, output, base);
}

function genFileList(input, output, base) {
	var folders = new OutFile(format(output + "folders-%d.txt", input))
	var files = new OutFile(format(output + "files-%d.txt", input))
	var codebase = new File(base + chrome::versions[input]).getCanonicalPath();
	
	println("Input folder: %s", base);
	println("Output folder: %s", output);
	
	shell::directoryDFTravesal(codebase, excludePattern=@'\\.svn', func=function(x) {
		var folder =  new Folder(x.getCanonicalPath());
		var filelist = folder.scanFiles(@".+?\.(c|cc|cxx|cpp|h|hh|hxx|hpp)$", false);
		if (filelist.size() > 0) {
			var path = folder.getCanonicalPath();
			if (path.length() == codebase.length())
				path = ".";
			else
				path = path.substring(codebase.length() + 1);
			folders.writeln(path);
			for(var file: filelist)
				files.writeln(path + "/" + file.getName());
		}
	});
}